﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ArtClub.Model;

namespace ArtClub.DAL
{
	internal class ArtDB : IArtDb
	{
		ArtClubContext db = new ArtClubContext();

		public Art GetArt(int id)
		{
		    return (from a in db.Arts
					where a.Id == id
					select a).FirstOrDefault();
		}
		
		public List<Art> ListArtByName(string name)
		{
		    return (from a in db.Arts
					where a.Name.ToLower().Contains(name.ToLower())
					select a).ToList();
		}

		public List<Art> ListArt()
		{
		    return db.Arts.ToList();
		}


		public void Create(Art art)
		{
			db.Arts.Add(art);
			db.SaveChanges();
		}

		public void Update(Art art)
		{
			db.Arts.Attach(art);
			db.Entry(art).State = System.Data.Entity.EntityState.Modified;
			db.SaveChanges();
		}

		public void Delete(int id)
		{
			db.Arts.Remove(GetArt(id));
			db.SaveChanges();
		}
	}
}
